﻿using Microsoft.AspNetCore.Mvc;
using UpperComputer.Application;
using YFurion.Application;

namespace UpperComputer.Web.Entry.Controllers
{
    /// <summary>
    /// 菜单控制器
    /// </summary>
    [ApiDescriptionSettings(ApiGroupConst.USER_AUTHORIZATION)]
    public class MenuController : AuthorizeController
    {
        private readonly IBaseMenuService _menuService;

        /// <summary>
        /// 菜单控制器构造函数
        /// </summary>
        /// <param name="menuService">菜单服务</param>
        public MenuController(IBaseMenuService menuService)
        {
            _menuService = menuService;
        }

        /// <summary>
        /// 获取菜单集合
        /// </summary>
        /// <param name="baseMenuResultRequestDto"></param>
        /// <returns></returns>
        public async Task<List<BaseMenuResultDto>> Get([FromQuery] BaseMenuResultRequestDto baseMenuResultRequestDto)
        {
            baseMenuResultRequestDto.MaxResultCount = int.MaxValue;
            List<BaseMenuResultDto> baseMenuResultDtos = await _menuService.GetMenus(baseMenuResultRequestDto);
            return baseMenuResultDtos;
        }

        /// <summary>
        /// 根据id获取菜单
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task<BaseMenuResultDto> Get(long id)
        {
            BaseMenuResultDto baseMenuResultDto = await _menuService.Get(id );
            return baseMenuResultDto;
        }

        /// <summary>
        /// 新增菜单
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public async Task<BaseMenuResultDto> Post(BaseMenuDto dto)
        {
            BaseMenuResultDto entityDto = await _menuService.Post(dto);
            return entityDto;
        }

        /// <summary>
        /// 修改菜单
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public async Task<BaseMenuResultDto> Put(BaseMenuDto dto)
        {
            BaseMenuResultDto entityDto = await _menuService.Put(dto);
            return entityDto;
        }

        /// <summary>
        /// 删除菜单
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task<EntityDto> Delete(long id)
        {
            await _menuService.Delete( id );
            return new EntityDto { Id = id };
        }
    }
}
